package com.lp.multi.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: lp
 * @create: 2021-06-28 7:18
 * @description: 三大方法
 */
public class ExcutorsTest {
    public static void main(String[] args) {
        //单个线程
        //ExecutorService pool = Executors.newSingleThreadExecutor();
        //固定个数线程池
        //ExecutorService pool = Executors.newFixedThreadPool(5);
        //可伸缩个数线程池
        ExecutorService pool = Executors.newCachedThreadPool();
        try {
            for (int i = 0; i < 10; i++) {
                pool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"ok");
                });
            }
        }finally {
            //关闭线程池
            pool.shutdown();
        }


    }
}
